<template>
  <div class="goods">
    <div class="menu-wrapper" ref="meunList">
      <ul>
        <li class="menu-item" v-if="goods" v-for="item in goods">
          <div class="goods-class">
            <span class="goods-icon" v-show="item.type !==-1" :class="classMap[item.type]"></span> {{item.name}}
          </div>
        </li>
      </ul>
    </div>
    <div class="foods-wrapper" ref="foodsList">
      <ul>
        <li class="foods-class" v-for="item in goods">
          <h2 class="title">{{item.name}}</h2>

          <figure class="foods-list" v-for="foods in item.foods">
            <img width="57" height="57" class="foods-img" :src="foods.icon" alt="">
            <figcaption class="foods-info">
              <h3 class="foods-name">{{foods.name}}</h3>
              <p class="foods-common foods-description">{{foods.description}}</p>
              <p class="foods-common foods-other">
                <span class="sellCount">月售{{foods.sellCount}}份</span><span class="rating">好评率{{foods.rating}}%</span>
              </p>
              <p class="foods-common foods-price">
                <span class="discountprice">￥{{foods.price}}</span>
                <span class="price" v-show="foods.oldPrice">￥{{foods.oldPrice}}</span>
              </p>
            </figcaption>
          </figure>
      </li>
      </ul>
      
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll';
  const ERR_OK = 0;
export default {
  props: {
  },
  data(){
    return {
      goods:{},
      meunList:""
    }
  },
  created () {
    this.$http.get('/api/goods').then( (res) => {
        res = res.body;
        if (res.errno === ERR_OK) {
          this.goods = res.data;
          this.$nextTick(() => {
            // DOM 已经更新了
            this._scroll();
        });
        
     }
    });
    
    this.classMap=['decrease','discount','guarantee','invoice','special'];
  },
  methods: {
    _scroll () {  //使左右两个模块都滚动
      // console.log(this.$refs.meunList)
        this.meunList = new BScroll (this.$refs.meunList,{
          click: true
        });//传2个参数，第一个是DOM对象，第二个是JSON对象;
        this.foodsList = new BScroll (this.$refs.foodsList,{});//传2个参数，第一个是DOM对象，第二个是JSON对象;
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
  @import '../../common/scss/mixin.scss';
  .goods {
    display: flex;
    position: absolute;
    top: 174px;
    left: 0;
    bottom: 46px;
    width: 100%;
    overflow: hidden;
    .menu-wrapper {
      flex: 0 0 80px;
      width: 80px;
      background: #f3f5f7;
      .menu-item {
        display: table;
        margin: 0 12px;
        width: 56px;
        border-bottom: 1px solid rgba(7, 17, 27, 0.1);
        height: 54px;
        font-size: 0;
        &:last-child {
          border-bottom: none;
        }
        .goods-class {
          display: table-cell;
          vertical-align: middle;
          font-size: 12px;
          font-weight: 200;
          line-height: 14px;
          .goods-icon {
            display: inline-block;
            width: 12px;
            height: 12px;
            line-height: 14px;
            background-size: 12px 12px;
            background-repeat: no-repeat;
            vertical-align: top;
            &.decrease {
              @include bg-image ('decrease_3');
            }
            &.discount {
              @include bg-image ('discount_3');
            }
            &.guarantee {
              @include bg-image ('guarantee_3');
            }
            &.invoice {
              @include bg-image ('invoice_3');
            }
            &.special {
              @include bg-image ('special_3');
            }
          }
        }
      }
    }
    .foods-wrapper {
      flex: 1;
      .foods-class {
        .title {
          font-size: 12px;
          color: rgb(147, 153, 159);
          line-height: 26px;
          height: 26px;
          background: #f3f5f7;
          border-left: 2px solid #d9dde1;
          padding-left: 13px;
        }
        .foods-list {
          display: flex;
          margin: 0 18px;
          padding: 18px 0;
          border-bottom: 1px solid rgba(7, 17, 27, 0.1);
          &:last-child {
            border-bottom: none;
          }
          .foods-img {
            flex: 0 0 57px;
            width: 57px;
            margin-right: 10px;
          }
          .foods-info {
            .foods-name {
              font-size: 14px;
              color: rgb(7, 17, 27);
              line-height: 14px;
              margin: 2px 0px 8px 0px;
            }
            .foods-common {
              font-size: 10px;
              color: rab(147, 153, 159);
              line-height: 10px;
              color: rgb(147, 153, 159);
              margin-bottom: 8px;
              &:last-child {
                margin-bottom: 0;
              }
              &.foods-other {
                .sellCount {
                  margin-right: 12px;
                }
              }
              &.foods-price {
                .discountprice {
                  font-size: 14px;
                  color: rgb(240, 20, 20);
                  line-height: 14px;
                  font-weight: 700;
                }
                .price {
                  font-weight: 700;
                  font-size: 10px;
                  text-decoration: line-through;
                }
              }
            }
          }
        }
      }
    }
  }
</style>